package org.jwt.oauth.tools;

import javax.servlet.http.HttpServletRequest;
import org.jwt.oauth.constant.ConstantAttribute;
import org.jwt.oauth.exception.ServiceErrorStatus;
import org.jwt.oauth.exception.ServiceRunTimeException;

public class FusionTokenTools {

	public static String getTokenValue() {
		HttpServletRequest request = HttpServletTool.getRequest();
		String authorization = request.getHeader("Authorization");
		if (authorization == null || authorization.length() == 0) {
			return null;
		}
		String[] split = authorization.split(ConstantAttribute.BEARER);
		if (split == null || split.length < 2) {
			throw new ServiceRunTimeException(ServiceErrorStatus.PARAMETER_ERROR);
		}
		String tokenValue = split[split.length - 1].trim();
		return tokenValue;
	}
}
